chrome.tabs.onUpdated.addListener(onUpdate);
chrome.tabs.onCreated.addListener(onCreate);
chrome.webNavigation.onCommitted.addListener(onCommited);

var llog = [];
var createCount = 0;

chrome.browserAction.onClicked.addListener(function() {
  //window.open('place.html', 'testwindow', 'width=700,height=600');
  alert("go!");
  llog.length = 0;
});


function onUpdate(tabId, changeInfo, tab){
    if (changeInfo.status == 'complete') {
        //alert("Update! id:"+tab.id+" opener:"+tab.openerTabId);
        var title = tab.title;
        var id = tab.id;
        llog.push({'id':id, 'title':title});
    }
}

function onCreate(tab){
        //alert("Create! id:"+tab.id+" opener:"+tab.openerTabId);
        //tab.openerTabId = null;

        var title = tab.title;
        var id = tab.id;
        llog.push({'id':id, 'title':title}); 
}

function onCommited(details){
    var type = details.transitionType;
    var urls = ["www.google.ru/url?sa=","chrome:"];
    var types = ["link", "typed", "auto_bookmark"];  
    var error_reason = "";

    if (types.indexOf(type)==-1){
        error_reason = "type_is_unsupported";
    }

    urls.forEach(function(data){
        if (details.url.toLowerCase().indexOf(data)+1>0){
            error_reason = "url_in_blacklist";
        }
    });

    if (error_reason == ""){
        alert (type+"@@@@"+details.transitionQualifiers+"@@@@"+decodeURI(details.url));
    } else {
        //alert(error_reason);
    }

}
